
class P784_39643 {

	public static void main(String[] args) {
		int cases = Integer.parseInt(readLn());
		
		for (int k = 0; k < cases; k++) {
			process();
		}
	}
	
	private static void process() {
		char[][] land = new char[30][80];
		
		int lineIndex = 0;
		
		String line = readLn();
		
		int xStart = -1;
		int yStart = -1;
		
		while (line.charAt(0) != '_') {
			
			for (int k = 0; k < line.length(); k++) {
				land[lineIndex][k] = line.charAt(k);
				
				if (land[lineIndex][k] == '*') {
					xStart = k;
					yStart = lineIndex;
				}
				
			}
			lineIndex++;
			
			line = readLn();
		}
		
		StringBuffer sb = new StringBuffer("");
		
		for (int i = 0; i < land.length; i++) {
			for (int j = 0; j < land[i].length; j++) {
				char c = land[i][j];
				
				if (c == 'X' || c == '#' || c == ' ') sb.append(c);
				else break;
				
			}
			
			sb.append("\n");
			
		}
		
		land[yStart][xStart] = ' ';
		
		process(land, land.length, land[0].length, yStart, xStart);
		
		sb = new StringBuffer("");
		
		for (int i = 0; i < land.length; i++) {
			for (int j = 0; j < land[i].length; j++) {
				char c = land[i][j];
				
				if (c == 'X' || c == '#' || c == ' ') sb.append(c);
				else break;
				
			}
			
			sb.append("\n");
			
		}
		
		System.out.println(sb.toString().trim());
		System.out.println(line);
		
	}

	private static void process(char[][] land, int iLength, int jLength, int i, int j) {
		
		if (j >= 0 && j < jLength && i >= 0 && i < iLength) {
			
			if (land[i][j] != ' ') return;
			
			land[i][j] = '#';
			
			process(land, iLength, jLength, i, j + 1);
			process(land, iLength, jLength, i, j - 1);
					process(land, iLength, jLength, i + 1, j + 1);
					process(land, iLength, jLength, i + 1, j );
					process(land, iLength, jLength, i + 1, j - 1);
					process(land, iLength, jLength, i - 1, j + 1 );
					process(land, iLength, jLength, i - 1, j );
					process(land, iLength, jLength, i - 1, j - 1 );
		}
		
		
	}

	static String readLn() {
		String newLine = System.getProperty("line.separator");
		StringBuffer buffer = new StringBuffer();
		int car = -1;
		try {
			car = System.in.read();
			while ((car > 0) && (car != newLine.charAt(0))) {
				buffer.append((char) car);
				car = System.in.read();
			}
			if (car == newLine.charAt(0))
				System.in.skip(newLine.length() - 1);
		} catch (java.io.IOException e) {
			return (null);
		}
		if ((car < 0) && (buffer.length() == 0))
			return (null);
		return (buffer.toString()).trim();
	}
	
}
